
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

version = bot_version
def docker_bot_name = 'oiot-bot'

dependencies {

	implementation 'org.springframework.boot:spring-boot-starter-actuator'
	implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-security'
 	implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
 	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

	implementation 'jakarta.json:jakarta.json-api:2.1.1'

	implementation 'org.telegram:telegrambots:6.7.0'
    implementation 'com.google.code.gson:gson:2.7'

	runtimeOnly 'com.h2database:h2'

	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

jar {
    enabled = false
}

tasks.register('buildDockerImage') {
    group 'docker'
    def tag = docker_bot_name + ':' + version
    doLast {
        exec {
            workingDir '../'
            commandLine 'docker', 'build', '-t', tag, '.'
        }
    }
}

tasks.register('saveDockerImage') {
    group 'docker'
    def tarName = docker_bot_name + '-' + version + '.tar'
    doLast {
        exec {
            workingDir '.'
            commandLine 'docker', 'save', '-o', './build/' + tarName, docker_bot_name
        }
    }
}

tasks.register('send') {
    group 'docker'
    def tar = './build/' + docker_bot_name + '-' + version + '.tar'
    def destination = System.getenv("USER") + '@' + System.getenv("SERVER") + ':/home/' + System.getenv("USER") + '/'
    doLast {
        exec {
            workingDir '.'
            commandLine 'scp', tar, destination
        }
    }
}